package com.lz.football.module.rankinglist
{
	import com.common.utils.Reflection;
	import com.liangzhong.events.ModuleEvent;
	import com.liangzhong.events.RankingListEvent;
	import com.liangzhong.model.AppData;
	import com.lz.football.module.rankingList.IRankingList;
	
	import common.BaseView.BaseView;
	import common.comp.TabButtonBar;
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	import lz.controls.LButton;
	
	public class RankingListView extends BaseView implements IRankingList
	{
		
		/**
		*选项卡 
		*/		
		private var buttonBar :TabButtonBar;
		
		/**
		 *综合排名  
		 */
		private var _comRanking:ComRanking;
		/**
		 *国家排行 
		 */
		private var _nationRanking:NationRanking;
		
		/**
		 * 
		 */
		private var contain:MovieClip;
		public function RankingListView()
		{
			super();
		}
		override public function initUI(view:Object=null):void
		{
			symbolSkin = Reflection.createInstance("com.lz.modul.rankingListview");
			this.addChild(symbolSkin);
			_windowBg = symbolSkin.windowBg;
			contain = symbolSkin.contain;
			isDrag = true;
			isCloseBtn = true;
			moveClose(_windowBg.width - 30,35);
			_viewHeight = symbolSkin.height;
			_viewWidth = symbolSkin.width;
			var i :int = 0;
			var lbtn :LButton;
			var lbtns :Array = [];
			buttonBar = new TabButtonBar();
			for(i = 0;i<=7;i++)
			{
				lbtn = new LButton(symbolSkin["buttonBar"]["skin_" + i]);
				lbtn.enable = true;
				lbtns.push(lbtn);
			}
			buttonBar.setButtons(lbtns);
			buttonBar.selectTabButton(lbtns[0]);
			
			onResizeHandler();
			addEvtListener();
			onTabChangeHandler();
		}
		override public function addEvtListener():void
		{
			buttonBar.addEventListener(Event.CHANGE,onTabChangeHandler);
		}
		private function onTabChangeHandler(event:Event = null):void
		{
			update();
			var selectType :int = buttonBar.selectType;
//			this.dispatchEvent(new RankingListEvent(RankingListEvent.REQUEST_RANK_INFOBYTYPE,{type:selectType+1}));
			while(contain.numChildren)
			{
				contain.removeChildAt(0);
			}
			
			var sp:Sprite;
			switch(selectType)
			{
				case 0:
				case 1:
				case 2:
				case 3:
				case 4:
				case 5:
					
				case 6:
				
					if(_comRanking == null)
					{
						_comRanking = new ComRanking();
						_comRanking.initUI();
					}
					_comRanking.setType(selectType);
					sp = _comRanking;
					break;
				case 7:
					if(_nationRanking == null)
					{
						_nationRanking = new NationRanking();
						_nationRanking.initUI();
					}
					sp = _nationRanking;
					break;
			}
			contain.addChild(sp);
			rankingInfo(null);
		}
		override public function onCloseHandler(event:MouseEvent):void
		{
			this.dispatchEvent(new ModuleEvent(ModuleEvent.REMOVE_MODULE));
			
		}
		override public function removeEvtListener():void
		{
			super.removeEvtListener();
			buttonBar.removeEventListener(Event.CHANGE,onTabChangeHandler);
		}
		override public function destroyView():void
		{
			removeEvtListener();
			buttonBar.destroyView();
			if(_comRanking != null)_comRanking.destroyView();
			_comRanking = null;
			if(_nationRanking != null)_nationRanking.destroyView();
			_nationRanking = null;
			super.destroyView();
			
		}
		/**
		 *获得新的排名信息 
		 * @param $obj
		 * 
		 */		
		public function rankingInfo($obj:Object):void
		{
			var selectType :int = buttonBar.selectType;
			var obj:Object
			switch(selectType)
			{
				case 0:
					
				case 1:
					
				case 2:
					
				case 3:
					
				case 4:
					
				case 5:
					
				case 6:
					obj = AppData.getInstance().rankingListDateManager._dic[selectType];
					_comRanking.setDate(obj);
					break;
				case 7:
					_nationRanking.nationDate();
					break;
			}
		}
		/**
		 *更新显示数据 
		 * 
		 */
		public function update():void
		{
			var selectType :int = buttonBar.selectType;
			if(AppData.getInstance().rankingListDateManager._dic[selectType] == null || (AppData.getInstance().time - AppData.getInstance().rankingListDateManager._dic[selectType].time) > 3600)
				this.dispatchEvent(new RankingListEvent(RankingListEvent.REQUEST_RANK_INFOBYTYPE,{type:selectType}));

		}
				
	}
}